<?php

namespace app\common\model\order;

use app\admin\model\Admin;
use think\Model;


class Order extends Model
{

    // 表名
    protected $name = 'order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'timestamp';
    protected $dateFormat="Y-m-d H:i:s";

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'cardType_text',
        'tradeType_text'
    ];
    

    
    public function getCardtypeList()
    {
        return ['C' => __('Cardtype c'), 'D' => __('Cardtype d')];
    }

    public function getTradetypeList()
    {
        return ['1' => __('Tradetype 1'), '2' => __('Tradetype 2')];
    }


    public function getCardtypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cardType']) ? $data['cardType'] : '');
        $list = $this->getCardtypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTradetypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['tradeType']) ? $data['tradeType'] : '');
        $list = $this->getTradetypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function admin()
    {
        return $this->hasOne(Admin::class, 'id', 'store_id');
    }
}
